package com.ithzl.capacity.service.impl;

import com.ithzl.capacity.mapper.EntryFormMapper;
import com.ithzl.capacity.pojo.EntryForm;
import com.ithzl.capacity.pojo.EntryForm_02;
import com.ithzl.capacity.pojo.dto.EvaluateBriefDTO;
import com.ithzl.capacity.pojo.dto.EvaluatePageDTO;
import com.ithzl.capacity.pojo.dto.WorksControlBrief;
import com.ithzl.capacity.pojo.dto.WorksPageDTO;
import com.ithzl.capacity.service.WorksService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorksServiceImpl implements WorksService {

    @Autowired
    EntryFormMapper entryFormMapper;

    @Override
    public List<WorksControlBrief> selectWorksList(WorksPageDTO worksPageDTO) {
        List<WorksControlBrief> worksControlBriefList = entryFormMapper.selectEntryTeamList(worksPageDTO);
        return worksControlBriefList;
    }

    @Override
    public EntryForm selectWorksById(int entryFormId) {
        EntryForm entryForm = entryFormMapper.selectEntryForm(entryFormId);
        return entryForm;
    }

    @Override
    public List<EvaluateBriefDTO> selectEvaluateList(EvaluatePageDTO evaluatePageDTO) {

        List<EvaluateBriefDTO> evaluateBriefDTOList = entryFormMapper.selectEvaluateList(evaluatePageDTO);
        return evaluateBriefDTOList;
    }

    @Override
    public EntryForm_02 selectEvaluate(int entryFormId) {
        //获取报名表中所有的数据
        EntryForm entryForm = entryFormMapper.selectEntryForm(entryFormId);
        EntryForm_02 entryForm_02 = new EntryForm_02();
        BeanUtils.copyProperties(entryForm, entryForm_02);
        //获取审评的内容
        Map<String, String> map = entryFormMapper.selectOpinion(entryFormId);

        //审评内容和报名表结合作为作品的最终成绩展示
        entryForm_02.setJudgeName(map.get("judgeName"));

        Object value = map.get("judgeUserId");
        String id;
        if (value instanceof String) {
            id = (String) value;
        } else if (value instanceof Integer) {
            id = value.toString();
        } else {
            id=null;
        }

        int idInt=Integer.parseInt(id);
        entryForm_02.setJudgeUserId(idInt);
        entryForm_02.setOpinion(map.get("opinion"));
        return entryForm_02;


    }
}
